<template>
  <!-- 回收订单  售后列表 -->
  <div class="app-container backorder_page">
    <el-form v-if="!pageType" :model="queryParams" ref="queryForm" :inline="true" class="search-form-new" label-width="90px">
      <el-form-item label="售后编号" prop="afterNo">
        <el-input v-model="queryParams.afterNo" placeholder="请输入售后编号" clearable />
      </el-form-item>
      <!-- <el-form-item label="回收单号" prop="no">
        <el-input v-model="queryParams.no" placeholder="请输入回收单号" clearable />
      </el-form-item> -->
      <el-form-item label="游戏账号" prop="hsAccountNumber">
        <el-input v-model="queryParams.hsAccountNumber" placeholder="请输入游戏账号" clearable />
      </el-form-item>
      <el-form-item label="时间" prop="">
        <el-date-picker clearable v-model="timer" value-format="yyyy-MM-dd" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item class="btns">
        <el-button type="primary" icon="el-icon-search" @click="search" class="zdy-btn">搜索</el-button>
        <el-button icon="el-icon-refresh" type="warning" plain @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>
    <div class="customTab" v-loading="loading">
      <el-tabs type="border-card" v-model="actived" @tab-click="tabChange" v-loading="loading">
        <el-tab-pane :label="tab.label" :name="i" v-for="(tab,i) in commonMaps.backAfterStatesMap" :key="i">
          <div class="table_box" v-if="tableData.records&&tableData.records.length">
            <div class="table_row" v-for="item in tableData.records " :key="item.id">
              <backOrderAfterItem :orderItem="item" :userType="userType">
                <el-button type="text" @click="openShouhou(item.id)">查看详情</el-button>

                <el-button type="text" @click="openShouhou(item.id,'guarant')" v-if="userType=='guarant'&&item.status!=4 &&(
                    (!item.status||item.status==1)
                    ||(item.status==2&&(item.guaranteeRefundStatus==4)))">处理售后
                </el-button>

                <el-button type="text" @click="openShouhou(item.id,'guarant')" v-if="item.status==1 ">处理售后
                </el-button>


              </backOrderAfterItem>
            </div>
          </div>
          <div v-else>
            <el-empty description="暂无数据"></el-empty>
          </div>
        </el-tab-pane>
      </el-tabs>
    </div>
    <div class="pages-box">
      <pagination v-show="tableData.total > 0" :total="tableData.total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />
    </div>

    <!--  2023 12 04 新增 -->
    <ShouhouDetailDialog ref="ShouhouDetailDialog"></ShouhouDetailDialog>
  </div>
</template>

<script>
import onSelfApi from "@/api/retrieveManage/onSelf.js";
import backOrderAfterItem from "../components/backOrderAfterItem.vue";
import ShouhouDetailDialog from "../components/ShouhouDetailDialog.vue";
export default {
  name: "BackorderAfterList",
  props: ["pageType", "backOrderId"],
  components: {
    backOrderAfterItem,
    ShouhouDetailDialog,
  },
  data() {
    return {
      loading: false,
      tableData: {
        records: [],
        total: 0,
      },
      actived: "0",
      gameList: [],
      timer: [],
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        hsAccountNumber: "",
        createTimeStart: "",
        createTimeEnd: "",
        status: "",
        afterNo: "",
        backClueOrderId: "",
      },
      userType: "",
    };
  },
  computed: {
    tenantInfo() {
      return this.$store.getters.shopInfo;
    },
  },
  // watch: {
  //   pageType: {
  //     handler(newVal) {
  //       if (newVal) {
  //         this.userType = newVal;
  //       }
  //     },
  //     immediate: true,
  //   },
  //   backOrderId: {
  //     handler(newVal) {
  //       if (newVal) {
  //         this.queryParams.backClueOrderId = newVal;
  //         this.getList();
  //       }
  //     },
  //     immediate: true,
  //   },
  // },
  created() {
    // 获取页面类型
    // userType
    if (this.$router.currentRoute.query.orderStatus) {
      this.actived = this.$router.currentRoute.query.orderStatus;
      this.queryParams.status =
        this.$router.currentRoute.query.orderStatus;
    }
    if (this.$route.query && this.$route.query.userType == 17) {
      // 包赔端的售后处理页面
      this.userType = "guarant";
      this.getList();
    } else if (this.$route.path == "/recycleManage/backorderAfterList") {
      this.userType = "";
      this.getList();
    }
  },
  activated() {
    if (this.$router.currentRoute.query.orderStatus) {
      this.actived = this.$router.currentRoute.query.orderStatus;
      this.queryParams.orderStatus =
        this.$router.currentRoute.query.orderStatus;
    }
    this.getList();
  },

  methods: {
    // 获取订单列表
    getList() {
      this.loading = true;
      if (this.timer && this.timer.length) {
        this.queryParams.createTimeStart = this.timer[0];
        this.queryParams.createTimeEnd = this.timer[1] + " " + "23:59:59";
      } else {
        this.queryParams.successTimeStart = "";
        this.queryParams.successTimeEnd = "";
      }
      if(this.backOrderId){
        console.log("%c Line:130 🥒 this.backOrderId", "color:#7f2b82", this.backOrderId);
        this.queryParams.backClueOrderId = this.backOrderId;
      }
      if(this.tenantInfo){
        // console.log("%c Line:139 🥚 tenantInfo", "color:#ed9ec7", this.tenantInfo.tenantId);
        this.queryParams.buyerTenantId = this.tenantInfo.tenantId

      }

      onSelfApi.getbackClueOrderAfterList(this.queryParams).then((response) => {
        this.tableData.records = [];
        this.tableData.records = response.rows;
        this.tableData.total = response.total;
        this.loading = false;
      });
    },

    // tabs切换时触发
    tabChange(e) {
      // this.tableData.records = [];
      this.queryParams.status = e.name;
      if (e.name == 0) {
        this.queryParams.status = "";
      }
      this.$nextTick(() => {
        this.resetQuery();
      });
    },

    // 售后详情弹窗
    openShouhou(id, flag) {
      if (flag == "guarant") {
        // 立即处理  告知弹出窗
      }
      this.$refs.ShouhouDetailDialog.open(id, flag);
    },

    // 搜索
    search() {
      this.queryParams.pageNum = 1;
      this.getList();
    },

    //重置
    resetQuery() {
      this.queryParams.pageNum = 1;
      this.queryParams.hsAccountNumber = "";
      this.queryParams.createTimeStart = "";
      this.queryParams.createTimeEnd = "";
      this.queryParams.afterNo = "";
      this.queryParams.backClueOrderId = "";
      this.timer = [];
      this.getList();
    },
  },
};
</script>
<style lang="scss" scoped>
.table_box {
  padding: 0 !important;
  box-shadow: none !important;
}
</style>